#region Summary

// 
// Owner : JackieHan 
// 
// Solution : LearnSolution 
// 
// Project : JackieHan.NHibernate3.Test
// 
// File : TestListMapping.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : Summary
// 
// History : 
//			2010-09-18 23:24:53	    Create 
// 

#endregion

#region Using

using System;
using System.Collections.Generic;
using JackieHan.NHibernate3.Domain;
using JackieHan.NHibernate3.Repository;
using NUnit.Framework;

#endregion

namespace JackieHan.NHibernate3.Test
{
    /// <summary> 
    /// Summary
    /// </summary>
    [TestFixture]
    public class TestListMapping
    {
        [Test]
        public void TestElementList()
        {
            ListOfElements item = new ListOfElements
                                      {
                                          CreateDate = DateTime.Now,
                                          Creator = "admin",
                                          Elements = new List<string> { "aaa", "bbb", "ccc", "ddd" },
                                          Updator = "admin",
                                          LastUpdateDate = DateTime.Now,
                                          Version = 1
                                      };
            ListOfElementsRepository db = new ListOfElementsRepository();
            db.Save(item);
        }

        [Test]
        public void TestComponentList()
        {
            ListOfComponents item = new ListOfComponents
                                      {
                                          CreateDate = DateTime.Now,
                                          Creator = "admin",
                                          Updator = "admin",
                                          LastUpdateDate = DateTime.Now,
                                          Components = new List<ComponentList>
                                                           {
                                                               new ComponentList{IntProperty = 1,StringProperty="aaa"},
                                                               new ComponentList{IntProperty = 2,StringProperty="bbb"},
                                                               new ComponentList{IntProperty = 3,StringProperty="ccc"},
                                                               new ComponentList{IntProperty = 4,StringProperty="ddd"}
                                                           },
                                          Version = 1
                                      };
            ListOfComponentsRepository db = new ListOfComponentsRepository();
            db.Save(item);
        }

        [Test]
        public void TestOneToManyList()
        {
            ListOfOneToMany item = new ListOfOneToMany
                                     {
                                         CreateDate = DateTime.Now,
                                         Creator = "admin",
                                         Updator = "admin",
                                         LastUpdateDate = DateTime.Now,
                                         Version = 1
                                     };
            OneToManyList child1 = new OneToManyList { OneToMany = item };
            OneToManyList child2 = new OneToManyList { OneToMany = item };
            OneToManyList child3 = new OneToManyList { OneToMany = item };
            OneToManyList child4 = new OneToManyList { OneToMany = item };
            item.OneToMany = new List<OneToManyList> { child1, child2, child3, child4 };

            ListOfOneToManyRepository db = new ListOfOneToManyRepository();
            db.Save(item);
        }

        [Test]
        public void TestManyToManyList()
        {
            ManyToManyList child1 = new ManyToManyList { IntProperty = 1, StringProperty = "aaa" };
            ManyToManyList child2 = new ManyToManyList { IntProperty = 1, StringProperty = "aaa" };

            ListOfManyToMany item1 = new ListOfManyToMany
                                         {
                                             CreateDate = DateTime.Now,
                                             Creator = "admin",
                                             LastUpdateDate = DateTime.Now,
                                             Updator = "admin",
                                             Version = 1,
                                             ManyToMany = new List<ManyToManyList> { child1, child2 }
                                         };
            ListOfManyToMany item2 = new ListOfManyToMany
                                       {
                                           CreateDate = DateTime.Now,
                                           Creator = "admin",
                                           LastUpdateDate = DateTime.Now,
                                           Updator = "admin",
                                           Version = 1,
                                           ManyToMany = new List<ManyToManyList> { child1, child2 }
                                       };
            child1.ManyToMany = new List<ListOfManyToMany> { item1, item2 };
            child2.ManyToMany = new List<ListOfManyToMany> { item1, item2 };

            ListOfManyToManyRepository db = new ListOfManyToManyRepository();
            db.Save(new List<ListOfManyToMany> { item1, item2 });
        }
    }
}